#coding:utf-8
'''
Created on 2017-06-12

@author: sandy
'''

import os
import json
from pycommon import RemoteManager
from pycommon import Utils

class Config(object):
    
    def __init__(self):
        self.rundir = os.path.dirname(__file__)
        self.server_ip = u"127.0.0.1"
        self.server_port = 0
        self.max_client = 0
        self.max_packet_size = 0

    
    def onRemoteConfig(self, cfgname, jf):
        ctype,cname = cfgname.split(u".")
        if ctype==u'server'+unicode(RemoteManager.instance.sid) and cname==u'serverconfig':
            self.loadFromJson(jf)
    
    #加载同目录文件夹下的配置文件
    def loadFromFile(self):
        cf = json.load(file(os.path.join(self.rundir,"serverconfig.json")), encoding='utf-8')
        self.loadFromJson(cf)
       
    def loadFromJson(self, cf):
        self.server_id = cf.get("server_id")
        self.server_ip = cf.get("server_ip")
        self.server_port = cf.get("server_port") 
        self.max_client = cf.get("max_client")
        self.web_ip = cf.get("web_ip")
        self.web_port = cf.get("web_port")   
        self.max_packet_size = cf.get("max_packet_size")
   
instance = Config()